package com.lxr.test5002.base;

import android.util.Log;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 描述:[线程池]
 * @author: Zsm
 * @Date: 2023/3/1 19:25
 */
public class ThreadPool {
    private static final String TAG = "ThreadPool";
    private static final ThreadPool instance = new ThreadPool();
    /**
     * 根据cup核心数设置线程池数量
     */
    private static int corePoolSize = Runtime.getRuntime().availableProcessors();

    /**
     * 最大线程池数量= cpu核心数*2+1
     */
    private static int maximumPoolSize = corePoolSize * 2 + 1;
    /**
     * 等待线程的存活时间
     */
    private static long keepAliveTime = 1000;

    /**
     * 等待线程存活时间的单位
     */
    private static TimeUnit timeUnit = TimeUnit.MICROSECONDS;
    private static ThreadPoolExecutor mThreadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, timeUnit, new LinkedBlockingDeque<>()); // 线程池

    public ThreadPool() {

    }

    public static ThreadPoolExecutor getInstance() {
        Log.i(TAG,"最大线程数："+maximumPoolSize+"   核心线程数量："+corePoolSize);
        return mThreadPoolExecutor;
    }



}
